<template>
	<view>
		<view class="comment">
			<view class="tipsbox z-margin-16 z-flex-0">
				<view class="tipsitem z-margin-l-16  z-padding-lr-16 z-font-24 z-radius-8" :class="{'active': active == 0}" @click="change(0)">
					全部（{{ num.goodPercent * 100 }}%好评）
				</view>
				<view class="tipsitem z-margin-l-16  z-padding-lr-16 z-font-24 z-radius-8" :class="{'active': active == 1}" @click="change(1)">
					好评（{{ num.goodNum }}）
				</view>
				<view class="tipsitem z-margin-l-16  z-padding-lr-16 z-font-24 z-radius-8" :class="{'active': active == 2}" @click="change(2)">
					有图（{{ num.imageNum }}）
				</view>
				<view class="tipsitem z-margin-l-16  z-padding-lr-16 z-font-24 z-radius-8" :class="{'active': active == 3}" @click="change(3)">
					中评（{{ num.middleNum }}）
				</view>
				<view class="tipsitem z-margin-l-16  z-padding-lr-16 z-font-24 z-radius-8" :class="{'active': active == 4}" @click="change(4)">
					差评（{{ num.badNum }}）
				</view>
			</view>
			<view class="mian-box">
				<scroll-view class="scroll-box z-padding-lr-32" scroll-y="true" :show-scrollbar="false" enhanced="true" bindscrolltolower="more">
					<block v-for="(item,index) in list">
						<comment :info="item"></comment>
					</block>
					<!-- <van-empty description="暂无评论" v-if="finish && list.length === 0" /> -->
					<u-empty mode="list" v-if="finish && list.length === 0" icon="http://cdn.uviewui.com/uview/empty/list.png">
					</u-empty>
				</scroll-view>
			</view>
		</view>
	</view>
</template>

<script>
	import http from '../../utils/http';
import comment from '@/component/comment.vue';
export default {
	components: {
		comment
	},
	data() {
		return {
			list: [],
			finish: false,
			loading: false,
			page: 1,
			num: '',
			type: '',
			id: '',
			active: 0
		};
	},
	onLoad(options) {
	    this.type = options.type
	    this.id = options.id
	    this.getInfo()
	    this.reload()
	  },
	methods: {
		change(e){
		    this.active = e
		    this.reload()
		},
		reload(){
		   this.list = []
		   this.page = 1
		   this.finish = false
		    this.getList()
		},
		more(){
		   this.page = ++this.page
		    this.getList()
		},
		getList(){
		    if(this.finish){
		      return 
		    }
		    if(this.loading){
		      return 
		    }
		   this.loading = true
		    let data = {
		      page: this.page,
		    }
		    if(this.type == 'goods'){
		      data['goods_id'] = this.id
		    }else if(this.type == 'skill'){
		      data['skill_id'] = this.id
		    }else if(this.type == 'shop'){
		      data['shop_id'] = this.id
		    }else if(this.type == 'user'){
		      data['user_id'] = this.id
		    }
		    if(this.active == 1){
		      data['score'] = 5
		    }else if(this.active == 2){
		      data['images'] = 1
		    }else if(this.active == 3){
		      data['score'] = 2
		    }else if(this.active == 4){
		      data['score'] = 1
		    }
		    http.get('comment/getlist', data).then(res => {
		      if(res.data.length === 0){
		        this.finish = true
		      }
		      let arr = this.list.concat(res.data)
		      this.list = arr
		      
		    }).finally(res => {
		      this.loading = false
		    })
		},
		getInfo(){
		    let data = {
		      type: this.type
		    }
		    if(this.type == 'goods'){
		      data['goods_id'] = this.id
		    }else if(this.type == 'skill'){
		      data['skill_id'] = this.id
		    }else if(this.type == 'shop'){
		      data['shop_id'] = this.id
		    }else if(this.type == 'user'){
		      data['user_id'] = this.id
		    }
		    http.get('comment/totalcomment', data).then(res => {
		     this.num = res.data
		    })
		  },
	}
};
</script>

<style>
.comment {
	height: 100vh;
	display: flex;
	flex-direction: column;
}
.tipsbox {
	display: flex;
	overflow-x: auto;
}
.tipsbox::-webkit-scrollbar {
	display: none;
}

.tipsitem {
	height: 56rpx;
	background-color: #fff;
	color: #6b738b;
	display: flex;
	align-items: center;
	justify-content: center;
	flex-shrink: 0;
	box-sizing: border-box;
}
.active {
	background-color: #62cb81;
	color: #fff;
}
.mian-box {
	flex: 1;
	overflow: hidden;
}

.scroll-box {
	height: 100%;
	box-sizing: border-box;
}
</style>
